library WhirlwindAbility initializer Init requires entities, utils, MoveSpeedUpBuff
    /*
    --------------------------------------------------------------------------
    # 剑刃风暴
    --------------------------------------------------------------------------
    */
    
    globals
        public integer ABILITY_ID = 'AOww'
    endglobals

    private function SpellEnd takes Spell spell returns nothing
        call Unit.get(spell.m_unit).addMoveSpeed(-400)
        call spell.destroy()
    endfunction

    private function SpellAction takes Spell spell returns nothing
        local real x = GetUnitX(spell.m_unit)
        local real y = GetUnitY(spell.m_unit)
        local real range = spell.m_rangeEffect
        local group g = NewGroup()
        local unit uf

        call GroupUnitsInArea(g, x, y, range)

        loop
            set uf = FirstOfGroup(g)
            exitwhen (uf == null)
            call GroupRemoveUnit(g, uf)

            if IsWidgetAlive(uf) /* 存活的
            */and IsUnitEnemy(uf, GetOwningPlayer(spell.m_unit)) /* 敌人
            */then
                call spell.damageUnit(uf)
            endif
        endloop

        call ReleaseGroup(g)
        set g = null
    endfunction

    private function anon_baca8ce0 takes nothing returns nothing
        local Spell spell = GetTimerData(GetExpiredTimer())

        if spell.m_count > 0 then
            if (IsWidgetAlive(spell.m_unit)) then
                call SpellAction(spell)
            else
                call SpellEnd(spell)
            endif
            set spell.m_count = spell.m_count - 1
        else
            call SpellEnd(spell)
        endif
    endfunction

    private function SpellEffect takes nothing returns nothing
        local Spell spell

        if not (IsWidgetAlive(SpellEvent.CastingUnit)) then
            return
        endif

        set spell = Spell.create(SpellEvent.CastingUnit, ABILITY_ID)

        set spell.m_rangeEffect = 250
        set spell.m_timeDurative = 7
        set spell.m_interval = 0.25
        set spell.m_count = R2I(spell.m_timeDurative / spell.m_interval)

        set spell.m_weaponType = WEAPON_TYPE_METAL_HEAVY_SLICE
        set spell.m_damageEffPath = "Abilities\\Spells\\Other\\EphemeralCut\\EphemeralCutSilver.mdx"
        set spell.m_attachPointName = "chest"
        set spell.m_amount = spell.m_interval * 110

        set spell.m_path = "Abilities\\Spells\\Orc\\Whirlwind\\Whirlwind.mdx"
        set spell.m_effect = AddSpecialEffectTarget(spell.m_path, spell.m_unit, "origin")

        call Unit.get(spell.m_unit).addMoveSpeed(400)

        call TimerStart(spell.getTimer(), spell.m_interval, true, function anon_baca8ce0)
    endfunction

    private function SpellChannel takes nothing returns nothing
    endfunction

    private function Init takes nothing returns nothing
        //call RegisterSpellChannelResponse(ABILITY_ID, SpellChannel)
        call RegisterSpellEffectResponse(ABILITY_ID, SpellEffect)
    endfunction

endlibrary
